from base import Calculator

class ChildCount(Calculator):
    """
    Simple counting childs
    """
    
    def __init__(self, relation_name):
        self.relation_name = relation_name
        return super(ChildCount, self).__init__()
    
    def set_signals(self, model):
        from django.db import signals
        from django.dispatch import dispatcher

        dispatcher.connect(create_superuser, sender=auth_app, signal=signals.post_syncdb)

        super(self, ChildCount).set_signals(model)
    
    def calc_self(self, obj):
        return getattr(obj, '%s_set' % self.relation_name).count()